﻿using System;
using System.Linq;
using System.Runtime.Serialization;

using Newtonsoft.Json;

namespace WpfApp4.Models.Config
{
    [Serializable]
    [DataContract]
    [JsonObject(MemberSerialization.OptIn)]
    public class MenuInfo
    {
        private static MenuInfo _instance = null;
        public static MenuInfo Instance { get => _instance ?? (_instance = new MenuInfo()); }


        [DataMember(IsRequired = true)]
        [JsonProperty(PropertyName = "menuItems")]
        public MenuConfig[] MenuItems { get; set; }

        [DataMember(IsRequired = true)]
        [JsonProperty(PropertyName = "settings")]
        public SettingConfig Settings { get; set; }
    }


    [Serializable]
    [DataContract]
    [JsonObject(MemberSerialization.OptIn)]
    public class MenuConfig
    {
        [DataMember(IsRequired = true)]
        [JsonProperty(PropertyName = "id")]
        public string Id { get; set; }

        [DataMember(IsRequired = true)]
        [JsonProperty(PropertyName = "name")]
        public string Name { get; set; }

        [DataMember(IsRequired = true)]
        [JsonProperty(PropertyName = "command")]
        public string Command { get; set; }

        [DataMember(IsRequired = true)]
        [JsonProperty(PropertyName = "commandParameter")]
        public string CommandParameter { get; set; }

        [DataMember(IsRequired = true)]
        [JsonProperty(PropertyName = "windowSize")]
        public string WindowSize { get; set; }

        [DataMember(IsRequired = true)]
        [JsonProperty(PropertyName = "openModel")]
        public OpenModel OpenModel { get; set; }

        [DataMember(IsRequired = true)]
        [JsonProperty(PropertyName = "menuItems")]
        public MenuConfig[] MenuItems { get; set; }

        public MenuConfig Clone()
        {
            var newMenu = new MenuConfig
            {
                Id = this.Id,
                Name = this.Name,
                Command = this.Command,
                CommandParameter = this.CommandParameter,
                WindowSize = this.WindowSize,
                OpenModel = this.OpenModel,
                MenuItems = this.MenuItems?.Select(m => m.Clone()).ToArray() ?? new MenuConfig[] { },
            };
            return newMenu;
        }
    }
}
